package com.jianyun.jyzs.receive;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;


import com.jianyun.jyzs.fragment.ReceiveFragment;
import com.jianyun.jyzs.utils.SysConstant2;

public class ContactModuleFmBroadCast {

	private BroadcastReceiver receiver;
	private LocalBroadcastManager mLocalBroadcastManager;

	public void receiveCast(final ReceiveFragment fm) {
		mLocalBroadcastManager = LocalBroadcastManager.getInstance(fm.getActivity());
		IntentFilter filter = new IntentFilter();
		filter.addAction(SysConstant2.act_addCommonContact);
		filter.addAction(SysConstant2.act_deleteCommonContact);
		// 设置广播的级别
		filter.setPriority(3);
		receiver = new BroadcastReceiver() {
			@Override
			public void onReceive(Context context, Intent intent) {
				String action = intent.getAction();
				if (action.equals(SysConstant2.act_addCommonContact)) {
					fm.onReceiveBroadCast(context, intent);
				}else if (action.equals(SysConstant2.act_deleteCommonContact)) {
					fm.onReceiveBroadCast(context, intent);
				}
			}
		};
		mLocalBroadcastManager.registerReceiver(receiver, filter);
	}

	/**
	 * 注销广播
	 */
	public void unReisterReceiv() {
		if (mLocalBroadcastManager != null && receiver != null) {
			mLocalBroadcastManager.unregisterReceiver(receiver);
		}
	}
}
